﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// 文件名：ClsIntoValidateDAL.cs
/// 作  者：Kidy
/// 时  间：2006.11.10
/// 说  明：ClsIntoValidateDAL类用于入库确认相关处理
/// </summary>
public class ClsIntoValidateDAL
{
    /// <summary>
    /// 数据库连接字符串
    /// </summary>
    private static string strSqlConnectionString = ConfigurationManager.AppSettings["SQLCONNECTIONSTRING"];

    /// <summary>
    /// 获取所有信息
    /// </summary>
    /// <param name="Co_ID">公司ID</param>
    /// <param name="User_ID">用户ID</param>
    /// <param name="Ds_ID">数据集ID</param>
    /// <returns>返回数据集</returns>
    public DataSet GetIntoValidateMains(string Co_ID, string User_ID, string Ds_ID)
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);

        SqlDataAdapter dat = new SqlDataAdapter("Pro_getDateSetByIntoAffirm", con);//Pro_GetDataSet //

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;
        //dat.SelectCommand.Parameters.Add("@co_id", Co_ID);
        //dat.SelectCommand.Parameters.Add("@user_id", User_ID);
        //dat.SelectCommand.Parameters.Add("@ds_id", Ds_ID);

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    /// <summary>
    /// 获取所有退货盘点从表信息
    /// <param name="Tm_On">盘点单号</param>
    /// </summary>
    /// <returns>返回退货从表信息数据集</returns>
    public DataSet GetIntoValidateChilds(string Dm_No)
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_GetSellBackChilds", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;
        dat.SelectCommand.Parameters.Add("@dm_no", Dm_No);

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    /// <summary>
    /// 用于查询窗口获取数据
    /// </summary>
    /// <returns></returns>
    public DataSet SearchIntoValidates()
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_QueryWinGetDataByIntoValidate", con);

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    /// <summary>
    /// 用于查询窗口获取数据
    /// </summary>
    /// <returns></returns>
    public DataSet SearchIntoValidateSets()
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_QueryWinGetDataByIntoValidate", con);

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    /// <summary>
    /// 模糊搜索入库确认
    /// </summary>
    /// <param name="Key">搜索关键字</param>
    /// <returns>返回数据集</returns>
    public DataSet SearchIntoValidateSets(string Key)
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_SearchIntoValidateSets", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;
        dat.SelectCommand.Parameters.Add("@key", Key);

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    /// <summary>
    /// 作废入库确认
    /// </summary>
    /// <param>供商编号</param>
    /// <param name="Is_Visible">作废状态1为临时作废，－1为彻底作废</param>
    /// <returns>返回作废是否成功</returns>
    public Boolean DeleteIntoValidateSet(string Ct_ID, int Is_Visible)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_DeleteIntoValidateSet", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@Ct_ID", SqlDbType.NVarChar, 20);
        com.Parameters["@Ct_ID"].Value = Ct_ID;
        com.Parameters.Add("@Is_Visible", SqlDbType.Int, 1);
        com.Parameters["@Is_Visible"].Value = Is_Visible;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 确认入库确认
    /// </summary>
    /// <param>供商编号</param>
    /// <param name="AuditStat">确认状态</param>
    /// <param name="Auditor">确认人</param>
    /// <returns>返回确认是否成功</returns>
    public Boolean AuditStatIntoValidateSet(string Ct_ID, int AuditStat, string Auditor)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AuditStatSetIntoValidate", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@Ct_ID", SqlDbType.NVarChar, 20);
        com.Parameters["@Ct_ID"].Value = Ct_ID;
        com.Parameters.Add("@is_audit", SqlDbType.Int);
        com.Parameters["@is_audit"].Value = AuditStat;
        com.Parameters.Add("@auditor", SqlDbType.NVarChar, 60);
        com.Parameters["@auditor"].Value = Auditor;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 增加入库确认
    /// </summary>
    /// <param>供商编号</param>
    /// <param>......</param>
    /// <returns>返回修改是否成功</returns>
    public Boolean AddIntoValidateSet(string strCt_ID, string strCt_Name, string strCt_Addr, string strCt_Linkman, string strCt_Phone,
        string strCt_Dept, int iCt_State, string Remark, string Oper)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AddIntoValidateSet", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@Ct_ID", SqlDbType.NVarChar, 20);
        com.Parameters["@Ct_ID"].Value = strCt_ID;
        com.Parameters.Add("@Ct_Name", SqlDbType.NVarChar, 20);
        com.Parameters["@Ct_Name"].Value = strCt_Name;
        com.Parameters.Add("@Ct_Addr", SqlDbType.NVarChar, 60);
        com.Parameters["@Ct_Addr"].Value = strCt_Addr;
        com.Parameters.Add("@Linkman", SqlDbType.NVarChar, 20);
        com.Parameters["@Linkman"].Value = strCt_Linkman;
        com.Parameters.Add("@Phone", SqlDbType.NVarChar, 20);
        com.Parameters["@Phone"].Value = strCt_Phone;
        com.Parameters.Add("@Ct_Dept", SqlDbType.NVarChar, 20);
        com.Parameters["@Ct_Dept"].Value = strCt_Dept;
        com.Parameters.Add("@oper", SqlDbType.NVarChar, 20);
        com.Parameters["@oper"].Value = Oper;
        com.Parameters.Add("@Ct_State", SqlDbType.Int);
        com.Parameters["@Ct_State"].Value = iCt_State;
        com.Parameters.Add("@Remark", SqlDbType.NVarChar, 255);
        com.Parameters["@Remark"].Value = Remark;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 修改入库确认
    /// </summary>
    /// <param>供商编号</param>
    /// <param>......</param>
    /// <returns>返回修改是否成功</returns>
    public Boolean UpDateIntoValidateSet(string strCt_ID, string strCt_Name, string strCt_Addr, string strCt_Linkman, string strCt_Phone,
        string strCt_Dept, int iCt_State, string Remark)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_UpDateIntoValidateSet", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@Ct_ID", SqlDbType.NVarChar, 20);
        com.Parameters["@Ct_ID"].Value = strCt_ID;
        com.Parameters.Add("@Ct_Name", SqlDbType.NVarChar, 20);
        com.Parameters["@Ct_Name"].Value = strCt_Name;
        com.Parameters.Add("@Ct_Addr", SqlDbType.NVarChar, 60);
        com.Parameters["@Ct_Addr"].Value = strCt_Addr;
        com.Parameters.Add("@Linkman", SqlDbType.NVarChar, 20);
        com.Parameters["@Linkman"].Value = strCt_Linkman;
        com.Parameters.Add("@Phone", SqlDbType.NVarChar, 20);
        com.Parameters["@Phone"].Value = strCt_Phone;
        com.Parameters.Add("@Ct_Dept", SqlDbType.NVarChar, 20);
        com.Parameters["@Ct_Dept"].Value = strCt_Dept;
        com.Parameters.Add("@Ct_State", SqlDbType.Int);
        com.Parameters["@Ct_State"].Value = iCt_State;
        com.Parameters.Add("@Remark", SqlDbType.NVarChar, 255);
        com.Parameters["@Remark"].Value = Remark;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

}

